package easyerp.controller;

import easyerp.entity.ProductRecord;
import easyerp.service.ProductRecordService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("/api/productrecords")
public class ProductRecordController {

    private final ProductRecordService productRecordService;

    // 构造函数注入（推荐）
    public ProductRecordController(ProductRecordService productRecordService) {
        this.productRecordService = productRecordService;
    }

    // 查询所有产品
    @GetMapping
    public List<ProductRecord> getAllProductRecords() {
        return productRecordService.getAllProductRecords();
    }

    // 根据 ID 查询产品
    @GetMapping("/{id}")
    public ProductRecord getProductRecordById(@PathVariable UUID id) {
        return productRecordService.getProductRecordById(id);
    }

    // 新增产品
    @PostMapping
    public ProductRecord insertProductRecord(@RequestBody ProductRecord productRecord) {
        return productRecordService.insertProductRecord(productRecord);
    }

    // 根据 ID 更新产品
    @PutMapping("/{id}")
    public ProductRecord updateProductRecord(@PathVariable UUID id, @RequestBody ProductRecord productRecord) {
        return productRecordService.updateProductRecord(id, productRecord);
    }

    // 根据 ID 删除产品
    @DeleteMapping("/{id}")
    public void deleteProductRecord(@PathVariable UUID id) {
        productRecordService.deleteProductRecord(id);
    }
}
